package com.linchong.concurrency.chapter2;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author:linchong
 * @CreateTime:2019-12-31 15:17
 * @Description:
 */
@Slf4j
public class TaxCalaculatorMain {

	private final static int MAX = 50;

	public static void main(String[] args) {

		/*这种方式计算税率，每次改变计算规则都得修改一遍代码，可以将税率的计算抽取出来为一个接口*/
		/*texCalculatorV1();*/
		TaxCalaculator taxCalaculator = new TaxCalaculator(10000d, 2000d, (s, b) -> s * 0.1 + b * 0.15);
		log.info("税费为：{}", taxCalaculator.calculate());


		final Runnable ticketWindow = () -> {
			int index = 1;
			while (index <= MAX) {
				log.info(Thread.currentThread() + "号码为：{}", (index++));
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		};
		Thread windowThread1 = new Thread(ticketWindow, "一号窗口");
		Thread windowThread2 = new Thread(ticketWindow, "二号窗口");
		Thread windowThread3 = new Thread(ticketWindow, "三号窗口");
		windowThread1.start();
		windowThread2.start();
		windowThread3.start();
	}

	/*private static void texCalculatorV1() {
		final TaxCalaculator calaculator = new TaxCalaculator(10000d,2000d){
			@Override
			protected double calcTax() {
				return getSalary() * 0.1*getBonus()*0.15;
			}
		};
		double tax = calaculator.calculate();
		System.out.println(tax);
	}*/
}
